package com.shierke.Ume.ui.activity.me

import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.shierke.Ume.R
import com.shierke.Ume.base.BaseActivity
import com.shierke.Ume.bean.VipBannerBean
import com.shierke.Ume.ui.adapter.me.VipBannerAdapter
import com.shierke.Ume.ui.fragment.me.VipOrderFragment
import com.shierke.Ume.ui.fragment.me.VipOrderLikeFragment
import com.shierke.Ume.util.click
import com.shierke.Ume.util.startActivity
import com.youth.banner.indicator.CircleIndicator
import com.youth.banner.listener.OnPageChangeListener
import kotlinx.android.synthetic.main.activity_vip_order.*


/**
 * Create by Ybx
 * on 2020-10-18
 * Desribe:
 */
class VipOrderActivity : BaseActivity() {

    companion object {

        fun startActivity(context: Context) {
            context.startActivity<VipOrderActivity>()
        }
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


        setContentView(R.layout.activity_vip_order)

        setActivityTitleHintText(getString(R.string.vip_order_activity_title))

        fragments.add(VipOrderFragment())
        fragments.add(VipOrderLikeFragment())

        val viewpagerAdapter = ViewpagerAdapter(supportFragmentManager)
        viewPager.adapter = viewpagerAdapter
        viewPager.currentItem = 0



        banner.addBannerLifecycleObserver(this)
            .setAdapter(VipBannerAdapter(arrayListOf<VipBannerBean>().apply {
                add(VipBannerBean())
                add(VipBannerBean())
            })).setBannerGalleryEffect(10, 5)



        banner.addOnPageChangeListener(object : OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                viewPager.currentItem = position
            }
        })


        payNum.click {
            DeblockingVistorsDialogActivity.startActivity(this)
        }
    }


    private var fragments = arrayListOf<Fragment>()

    inner class ViewpagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {

        override fun getCount() = fragments.size

        override fun getItem(position: Int) = fragments[position]


    }


    override fun onStart() {
        super.onStart()
        banner.start()
    }


    override fun onStop() {
        super.onStop()
        //停止轮播
        banner.stop()
    }

    override fun onDestroy() {
        super.onDestroy()
        //销毁
        banner.destroy()
    }

}